#!/usr/bin/python3
# -*- coding: utf-8 -*-


def jsonpath_replace(change_data, key_name, data_switch=None):
    """处理jsonpath数据"""
    _new_data = key_name + ''
    # print(list(enumerate(change_data)))
    for i in list(enumerate(change_data)):
        if i[1] == '$':
            pass
        elif data_switch is None and i[1] == "data" and i[0] == 1:
            _new_data += '.data'
        elif i[1][0] == '[' and i[1][-1] == ']':
            _new_data += "[" + i[1][1:-1] + "]"
        else:
            _new_data += '[' + '"' + i[1] + '"' + "]"
    return _new_data



if __name__ == '__main__':
    a=jsonpath_replace(change_data=['$', 'data', 'a', 'data'], key_name='self.__yaml_case', data_switch=False)
    print(a)
